<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" isELIgnored="false"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<link href="${pageContext.request.contextPath}/css/bootstrap/bootstrap.min.css" rel="stylesheet">
<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery/2.0.0/jquery.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/bootstrap/4.0.0/bootstrap.min.js"></script>

<html>
<head>
  <meta charset="UTF-8">
  <title>map</title>
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
  <script src="${pageContext.request.contextPath}/js/jquery.js"></script>
  <script src="${pageContext.request.contextPath}/js/echarts.min.js"></script>
  <script src="${pageContext.request.contextPath}/js/china.js"></script>
  <style>
    *{margin:0;padding:0}
    html,body{
      width:100%;
      height:100%;
      background-color: rgba(21, 25, 101);
    }
    .container{
      width: 768px;
      margin: 0 auto;
    }
    .header{
      height: 110px;
      background: rgba(228, 238, 223, 0.76);
    }
    .section{
      background-color: whitesmoke;
      min-height: 300px;
      border-radius: 10px;
    }
    .map{
      background-color: whitesmoke;
    }
    .box{
      padding: 10px;
    }
    h1{

      text-align: center;
      color: black;
    }
    #gettime{
      text-align: right;
      padding-top: 10px;
    }
    /*默认长宽比0.75*/
  </style>
</head>
<body>
<div class = "container">
  <div class="index" style="color: #1b1e21"><a href="foreHome">首页</a></div>
  <div class = "header">
    <div class="box">

    </div>
    <h1>当前全国疫情数据分布图</h1>
    <div id="gettime">

    </div>
  </div>

  <div class="section">
    <div class="nav"></div>
    <div class="map">
      <div id="main" style="border: 1px solid black; width: 766px; height: 600px;"></div>
    </div>
  </div>
</div>

<script type="text/javascript">
  var myChart = echarts.init(document.getElementById('main'));
  function setEchart(data){
    option = {
      tooltip: {
        formatter:function(params,ticket, callback){
          return params.seriesName+'<br />'+params.name+'：'+params.value
        }//数据格式化
      },
      visualMap: {
        //min: 0,
        //max: 1500,
        left: 'left',
        top: 'bottom',
        text: ['高','低'],//取值范围的文字
        inRange: {
          color: ['#e0ffff', 'red']//取值范围的颜色
        },
        show:true//图注
      },
      geo: {
        map: 'china',
        roam: false,//不开启缩放和平移
        zoom:1.2,//视角缩放比例
        label: {
          normal: {
            show: true,
            fontSize:'10',
            color: 'rgba(0,0,0,0.7)'
          }
        },
        itemStyle: {
          normal:{
            borderColor: 'rgba(0, 0, 0, 0.2)'
          },
          emphasis:{
            areaColor: 'whitesmoke',//鼠标选择区域颜色
            shadowOffsetX: 0,
            shadowOffsetY: 0,
            shadowBlur: 20,
            borderWidth: 0,
            shadowColor: 'rgba(0, 0, 0, 0.5)'
          }
        }
      },
      series : [
        {
          name: '当前确诊人数',
          type: 'map',
          geoIndex: 0,
          data:data
        }
      ]
    };

    myChart.setOption(option);
    myChart.on('click', function (params) {
      alert(params.name);
    });

    window.onresize=function(){
      myChart.resize();
    }
  }


  $.ajax({
    type:'get',
    url:'https://view.inews.qq.com/g2/getOnsInfo?name=disease_h5',
    dataType:'jsonp',
    success:function(res){
      //console.log(res.data);
      let obj = JSON.parse(res.data);
      console.log(obj);
      console.log(obj.areaTree[0].children);
      let arr=obj.areaTree[0].children;
      let mapArr=[]
      for(let i=0;i<arr.length;i++){
        let item={
          name:arr[i].name,
          value:arr[i].total.nowConfirm
        }
        mapArr.push(item)
      }
      console.log(mapArr);
      setEchart(mapArr)
      let time=obj.lastUpdateTime;
      $('#gettime').text('数据源最近更新时间：'+time);
    }
  })



  /*  setTimeout(function () {
        myChart.setOption({
            series : [
                {
                    name: '信息量',
                    type: 'map',
                    geoIndex: 0,
                    data:dataList
                }
            ]
        });
    },1000)*/
</script>
</body>
</html>